home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / cgazv4n3.zip / NETBIOS.C < prev    next >
C/C++ Source or Header  |  1990-01-27  |  4KB  |  178 lines

  1. /*******************  NETBIOS.C --- Listing 3  ***********************
  2.  * Author: Victor Volkman
  3.  * Purpose: Low-level Netbios functions
  4.  *
  5.  * Compiler: Microsoft C 5.1, Turbo C 2.0
  6.  *
  7.  * Source code may be freely used if authorship is acknowledged.
  8.  * Object code may be freely used.
  9.  *********************************************************************/
  10.  
  11. #include <dos.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include "netbios.h"
  15.  
  16. #if defined __TURBOC__
  17. #define _dos_getvect getvect
  18. #endif
  19.  
  20. #ifndef MAKEFD  /* fd = compiler generated function declaration file */
  21. #include "netbios.fd"
  22. #endif
  23.  
  24. extern int nb_debug;
  25.  
  26. int NetbiosCommand(use_block)
  27. NCB *use_block;
  28. {
  29.    struct SREGS SegRegs;
  30.    union REGS InRegs, OutRegs;
  31.    NCB far *temp = (NCB far *) use_block;  /* fetch full 32-bit address */
  32.  
  33.    segread(&SegRegs);
  34.    SegRegs.es = FP_SEG(temp);
  35.    InRegs.x.bx = FP_OFF(temp);
  36.    int86x(NETBIOS_INT, &InRegs, &OutRegs, &SegRegs);
  37.    return use_block->ret_code;
  38. }
  39.  
  40.  
  41. int IsNetbiosLoaded()
  42. {
  43.    void (interrupt far *NetbiosVector)();
  44.  
  45.    NetbiosVector = _dos_getvect(NETBIOS_INT);
  46.    /* printf("netbios vector %08lx\n",NetbiosVector); */
  47.    return !(FP_SEG(NetbiosVector) == 0x0000 ||  /* no value  */
  48.             FP_SEG(NetbiosVector) == 0xF000);   /* F0 = IRET */
  49. }
  50.  
  51.  
  52. int NetbiosAddName(new_name)
  53. char *new_name;
  54. {
  55.    NCB add_name;
  56.  
  57.    if (nb_debug) printf("NetbiosAddName(%s)\n",new_name);
  58.    memset(&add_name, 0, sizeof(NCB));
  59.    add_name.command = NETBIOS_ADD_NAME;
  60.    strcpy(add_name.name, new_name);
  61.    return NetbiosCommand(&add_name);
  62. }
  63.  
  64.  
  65. int NetbiosDeleteName(old_name)
  66. char *old_name;
  67. {
  68.    NCB delete_name;
  69.  
  70.    if (nb_debug) printf("NetbiosDeleteName(%s)\n",old_name);
  71.    memset(&delete_name, 0, sizeof(NCB));
  72.    delete_name.command = NETBIOS_DELETE_NAME;
  73.    strcpy(delete_name.name, old_name);
  74.    return NetbiosCommand(&delete_name);
  75. }
  76.  
  77.  
  78. int NetbiosHangup(lsn)
  79. SESSION lsn;
  80. {
  81.    NCB hangup;
  82.  
  83.    if (nb_debug) printf("NetbiosHangup(%d)\n",lsn);
  84.    memset(&hangup, 0, sizeof(NCB));
  85.    hangup.command = NETBIOS_HANGUP;
  86.    hangup.lsn = lsn;
  87.    return NetbiosCommand(&hangup);
  88. }
  89.  
  90.  
  91. int NetbiosReset()
  92. {
  93.    NCB reset;
  94.  
  95.    if (nb_debug) printf("NetbiosReset()\n");
  96.    memset(&reset, 0, sizeof(NCB));
  97.    reset.command = NETBIOS_RESET;
  98.    return NetbiosCommand(&reset);
  99. }
  100.  
  101.  
  102. int NetbiosSend(lsn,buffer,length)
  103. SESSION lsn;
  104. char *buffer;
  105. unsigned int length;
  106. {
  107.    NCB send;
  108.  
  109.    if (nb_debug) printf("NetbiosSend(%d,buffer,%d)\n",lsn,length);
  110.    memset(&send, 0, sizeof(NCB));
  111.    send.command = NETBIOS_SEND;
  112.    send.lsn = lsn;
  113.    send.buffer = (char far *)buffer;
  114.    send.length = length;
  115.    return NetbiosCommand(&send);
  116. }
  117.  
  118.  
  119. int NetbiosReceive(lsn,buffer,length)
  120. SESSION lsn;
  121. char *buffer;
  122. unsigned int length;
  123. {
  124.    NCB receive;
  125.  
  126.    if (nb_debug) printf("NetbiosReceive(%d,buffer,%d)\n",lsn,length);
  127.    memset(&receive, 0, sizeof(NCB));
  128.    receive.command = NETBIOS_RECEIVE;
  129.    receive.lsn = lsn;
  130.    receive.buffer = (char far *)buffer;
  131.    receive.length = length;
  132.    return NetbiosCommand(&receive);
  133. }
  134.  
  135.  
  136. int NetbiosCall(lsn_p, server_name, client_name, rto, sto)
  137. SESSION *lsn_p;
  138. char *server_name;
  139. char *client_name;
  140. unsigned char rto;   /* rto = Receive Time-Out */
  141. unsigned char sto;   /* sto = Send Time-Out    */
  142. {
  143.    NCB call;
  144.    int err;
  145.  
  146.    if (nb_debug)
  147.       printf("NetbiosCall(lsn_p,%s,%s,%d,%d)\n",server_name,client_name,
  148.               rto,sto);
  149.    memset(&call, 0, sizeof(NCB));
  150.    call.command = NETBIOS_CALL;
  151.    strcpy(call.call_name, server_name);
  152.    strcpy(call.name, client_name);
  153.    call.rto = rto;
  154.    call.sto = sto;
  155.    err = NetbiosCommand(&call);
  156.    *lsn_p = call.lsn;   /* save local session number */
  157.    return err;
  158. }
  159.  
  160.  
  161.  
  162. NCB listen;
  163.  
  164. int NetbiosListen(server_name, rto, sto)
  165. char *server_name;
  166. unsigned char rto;   /* rto = Receive Time-Out */
  167. unsigned char sto;   /* sto = Send Time-Out    */
  168. {
  169.    if (nb_debug)
  170.       printf("NetbiosListen(lsn_p,%s,%d,%d)\n",server_name,rto,sto);
  171.    memset(&listen, 0, sizeof(NCB));
  172.    listen.command = NETBIOS_LISTEN | NO_WAIT;
  173.    strcpy(listen.call_name, "*");      /* Listen for "anybody" */
  174.    strcpy(listen.name, server_name);
  175.    listen.rto = rto;
  176.    listen.sto = sto;
  177.    return NetbiosCommand(&listen);
  178. }